create or replace PACKAGE BODY pkg_html_utils
IS
   PROCEDURE p_make_select
      ( the_name VARCHAR2
      , the_match_val VARCHAR2
      , disabled CHAR DEFAULT 'N'      
      , the_attributes VARCHAR2 DEFAULT NULL )
   IS
   BEGIN
         
      IF disabled != 'Y' THEN
         htp.p( '<select name="'||the_name||'" '||the_attributes||'>' );
      ELSE
         htp.p( '<select name="'||the_name||'" disabled="disabled" '||the_attributes||'>' );
      END IF;
      
      FOR i IN option_list.FIRST..option_list.LAST LOOP
         IF ( the_match_val = option_list( i ).the_value )
         OR ( the_match_val IS NULL
            AND option_list( i ).the_value IS NULL )         
         THEN
            htp.p( '<option value="'||option_list( i ).the_value||'" selected="selected">'||option_list( i ).the_display||'</option>' );
         
         ELSE
            htp.p( '<option value="'||option_list( i ).the_value||'">'||option_list( i ).the_display||'</option>' );       
         END IF;     
      END LOOP;
      htp.p( '</select>' );
   
   EXCEPTION
      WHEN OTHERS THEN
         htp.p( '<select name="error">' );
         htp.p( '<option value="'||SQLCODE||'">'||SQLERRM||'</option>' );
         htp.p( '</select>' );
   END p_make_select;
   
   PROCEDURE clear_option_list
   IS
   BEGIN
      option_list.DELETE;
      option_list_index := 0;    
   END clear_option_list;
   
   PROCEDURE add_option
      ( the_value VARCHAR2
      , the_display VARCHAR2 )
   IS
   BEGIN 
      option_list_index := option_list_index + 1;
      option_list( option_list_index ).the_value := SUBSTR( the_value, 1, 400 );
      option_list( option_list_index ).the_display := SUBSTR( the_display, 1, 400 );
   END add_option;  
   
   PROCEDURE p_make_ul
      ( make_anchor IN VARCHAR2 DEFAULT 'N'
      , ul_attributes IN VARCHAR2 DEFAULT NULL
      , li_attributes IN VARCHAR2 DEFAULT NULL
      , a_attributes IN VARCHAR2 DEFAULT NULL )
   IS
   BEGIN
      htp.p( '<ul '||ul_attributes||'>' );
      FOR i IN option_list.FIRST..option_list.LAST LOOP
         IF make_anchor != 'N' THEN
           htp.p
              ( '<li '||li_attributes||'>'
              ||'<a href="'||option_list( i ).the_value||'" '||a_attributes||'>'
              ||option_list( i ).the_display
              ||'</a></li>' );      
         ELSE
           htp.p
              ( '<li '||li_attributes||'>'
              ||option_list( i ).the_display
              ||'</li>' );      
         
         END IF;
      END LOOP;
      htp.p( '</ul>' );
   EXCEPTION
      WHEN OTHERS THEN
         htp.p( '<ul>' );
         
         htp.p( '</ul>' );
   END p_make_ul;
   
END pkg_html_utils;
